# 定义用户的增删改查方法
from apps.PO.UserPO import UserPO
from apps.mapper.UserMapper import UserMapper


class UserService:
    # 构造方法
    def __init__(self, user_po: UserPO):
        self.user_id = user_po.user_id
        self.username = user_po.user_name
        self.password = user_po.password
        # 实例化UserMapper
        self.user_mapper = UserMapper()

    # 登录方法
    def login(self):
        return self.user_mapper.login(self.username, self.password)

    # 注册方法
    def register(self):
        return self.user_mapper.register(self.username, self.password)

    # 修改用户信息方法
    def update_user_info(self):
        return self.user_mapper.update_user(self.user_id, self.username, self.password)

    # 获取用户信息方法
    def get_user_info(self):
        return self.user_mapper.read_all_users()

    # 删除用户方法
    def delete_user(self):
        return self.user_mapper.delete_user(self.user_id)

